package cn.itcast.bos.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.bos.domain.Decidezone;
import cn.itcast.crm.domain.Customer;

@Controller
@Scope("prototype")
public class DecidedzoneAction extends BaseAction<Decidezone> {

	public String save(){
		decidezoneService.save(model);
		return NONE;
	}
	
	//定区分页查询
	public String pageQuery(){
		decidezoneService.pageQuery(pageBean);
		this.writePageBeanToJson(pageBean, new String[]{"detachedCriteria","currentPage","pageSize","subareas","decidezones"});
		return NONE;
	}
	
	//通过代理对象调用crm服务 查询未关联定区的用户
	public String findCustomernoassociation(){
		//代理对象向指定的crm服务发送调用请求
		List<Customer> list = customerService.findnoassociationCustomers();
		//将list序列化成json对象 写回客户端浏览器
		this.writeListToJson(list, new  String[]{"station","telephone","address","decidezone_id"});
		return NONE;
	}
	
	//通过代理对象调用crm服务查询已关联定区的用户
	public String findCustomersAssociation(){
		//代理对象向指定的crm服务发送调用请求
		List<Customer> list = customerService.findhasassociationCustomers(model.getId());
		//将list序列化成json对象 写回客户端浏览器
		this.writeListToJson(list, new  String[]{"station","telephone","address","decidezone_id"});
		return NONE;
	}
	
	private Integer[] customerIds;
	public void setCustomerIds(Integer[] customerIds) {
		this.customerIds = customerIds;
	}

	public String assigncustomerstodecidedzone(){
		customerService.assignCustomersToDecidedZone(customerIds, model.getId());
		return "list";
	}
}
